package co.yixiang.modules.hotTopic.rest;

import co.yixiang.api.ApiResult;
import co.yixiang.common.bean.LocalUser;
import co.yixiang.common.interceptor.AuthCheck;
import co.yixiang.modules.hotTopic.service.YxHotTopicService;
import co.yixiang.modules.hotTopic.service.dto.YxHotTopicPage;
import co.yixiang.modules.hotTopicComment.service.YxCommentService;
import co.yixiang.modules.hotTopicComment.service.dto.YxCommentDto;
import co.yixiang.modules.hotTopicComment.service.dto.YxCommentPage;
import co.yixiang.modules.hotTopicLike.service.YxLikeService;
import co.yixiang.modules.user.domain.YxUser;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: DaiALong
 * @Description:
 * @Date: Created in 2021/8/12 15:19
 */
@Slf4j
@RestController
@Api(value = "热门话题", tags = "热门话题:热门话题", description = "热门话题")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class YxAppHotTopicController {

    private final YxHotTopicService yxHotTopicService;
    private final YxCommentService yxCommentService;
    private final YxLikeService yxLikeService;

    /**
     * 获取热门话题分页列表
     *
     */
    @AuthCheck
    @GetMapping("/hotTopic/getHotTopicPage")
    @ApiOperation(value = "热门话题", notes = "热门话题")
    public ApiResult<Page<YxHotTopicPage>> getHotTopicPage(@RequestParam(value = "page",defaultValue = "1") int page, @RequestParam(value = "limit",defaultValue = "10") int limit) {
        return yxHotTopicService.getHotTopicPage(page,limit);
    }



    /**
     * 获取热门话题详情
     *
     */
    @AuthCheck
    @GetMapping("/hotTopic/getHotTopicDetails")
    @ApiOperation(value = "热门话题详情", notes = "热门话题详情")
    public ApiResult getHotTopicDetails(@RequestParam int hotTopicId) {
        return yxHotTopicService.getHotTopicDetails(hotTopicId);
    }


    /**
     * 获取热门话题评论分页列表
     *
     */
    @AuthCheck
    @GetMapping("/hotTopic/getHotTopicCommentPage")
    @ApiOperation(value = "热门话题评论", notes = "热门话题评论")
    public ApiResult<Page<YxCommentPage>> getHotTopicCommentPage(@RequestParam int hotTopicId, @RequestParam(value = "page",defaultValue = "1") int page, @RequestParam(value = "limit",defaultValue = "10") int limit) {
        return yxCommentService.getHotTopicCommentPage(hotTopicId,page,limit);
    }

    /**
     * 添加热门话题评论
     *
     */
    @AuthCheck
    @PostMapping("/hotTopic/saveHotTopicComment")
    @ApiOperation(value = "添加热门话题评论", notes = "添加热门话题评论")
    public ApiResult saveHotTopicComment(@RequestBody YxCommentDto yxCommentDto) {
        YxUser yxUser= LocalUser.getUser();
        return yxCommentService.saveHotTopicComment(yxCommentDto.getHotTopicId(),yxCommentDto.getContent(),yxUser.getUid());
    }

    /**
     * 点赞或取消点赞
     *
     */
    @AuthCheck
    @PostMapping("/hotTopic/saveOrDeleteHotTopicLike")
    @ApiOperation(value = "点赞或取消点赞", notes = "点赞或取消点赞")
    public ApiResult saveOrDeleteHotTopicLike(@RequestParam int hotTopicId) {
        YxUser yxUser= LocalUser.getUser();
        return yxLikeService.saveOrDeleteHotTopicLike(hotTopicId,yxUser.getUid());
    }

}
